package com.exam.controller;

import com.exam.pojo.*;
import com.exam.service.*;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class PaperController {
    @Resource
    private PaperMapService paperMapService;

    @Resource
    private PaperManageService paperManageService;

    @Resource
    private ChoiceQuestionService choiceQuestionService;
    @Resource
    private FillQuestionService fillQuestionService;
    @Resource
    private JudgeQuestionService judgeQuestionService;

    @GetMapping("/paper/{id}")
    public Map<Integer, List<?>> findById(@PathVariable("id") Integer paperId){
        Map<Integer, List<?>> map = new HashMap<>();
        map.put(1,choiceQuestionService.queryByPaperId(paperId));
        map.put(2,fillQuestionService.queryByPaperId(paperId));
        map.put(3,judgeQuestionService.queryByPaperId(paperId));
        return map;
    }
    @GetMapping("/manage/paper/{id}")
    public PaperManage findPaperManageById(@PathVariable("id") Integer id){
        return paperManageService.queryById(id);
    }

    @GetMapping("/manage/paper")
    public List<PaperManage> finPaperManageAll(){
        return paperManageService.queryAll();
    }
    @GetMapping("/manage/mypaper/{id}")
    public List<PaperManage> findPaperManageByPaperCreatorId(@PathVariable("id") Integer paperCreatorId){
        return paperManageService.queryByPaperCreatorId(paperCreatorId);
    }
    @GetMapping("/manage/paper/{pageNum}/{pageSize}")
    public PageInfo<PaperManage> findAllPaperManagePage(
            @PathVariable("pageNum") Integer pageNum,
            @PathVariable("pageSize") Integer pageSize){
        return paperManageService.queryAllPage(pageNum,pageSize);
    }

    @PutMapping("/manage/paper/update")
    public int updateById(@RequestBody PaperManage paperManage){
        return paperManageService.updateById(paperManage);
    }
    @DeleteMapping("/manage/paper/delete/{id}")
    public int deletePaperById(@PathVariable("id") Integer id){
        return paperManageService.deleteById(id);
    }


    @PostMapping("/manage/paper/add")
    public int addPaper(@RequestBody PaperManage paperManage){
        return paperManageService.add(paperManage);
    }

    @PostMapping("/manage/paper/map/add")
    public int addPaperMap(@RequestBody PaperMap paperMap){
        return paperMapService.add(paperMap);
    }

    @DeleteMapping("/manage/paper/map/delete/{paperId}/{questionType}/{questionId}")
    public int deletePaperMap(
            @PathVariable("paperId") Integer paperId,
            @PathVariable("questionType") Integer questionType,
            @PathVariable("questionId") Integer questionId){
        return paperMapService.delete(paperId,questionType,questionId);
    }

}
